import { fromJS } from 'immutable';
import axios from 'axios';
import * as constants from './constants';

const changeList = (data) => {
    return {
        type: constants.CHANGE_LIST,
        data: fromJS(data),
        totalPage: Math.ceil(data.length / 10)
    }
}

export const searchFocus = () => {
    return {
        type: constants.INPUT_CHANGE_FOCUS
    }
}

export const searchBlur = () => {
    return {
        type: constants.INPUT_CHANGE_BLUR
    }
}

export const getList = () => {
    return (dispatch) => {
        axios.get('/api/headerList.json').then((res) => {
            const data = res.data.data;
            dispatch(changeList(data)); 
        }).catch((err) => {
            console.log(err);
        })
    }
}

export const mouseEnter = () => {
    return {
        type: constants.ON_MOUSE_ENTER
    }
}

export const mouseLeave = () => {
    return {
        type: constants.ON_MOUSE_LEAVE
    }
}

export const getSwitchList = (page) => {
   return{
       type: constants.GET_CHANGE_LIST,
       page
   }
}
